package com.gxa.hualian.service.impl;

import com.gxa.hualian.exception.BusinessException;
import com.gxa.hualian.exception.ExceptionCode;
import com.gxa.hualian.mapper.UserMapper;
import com.gxa.hualian.pojo.User;
import com.gxa.hualian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author lijunlin
 * @date 2022/5/22
 * 在业务层的实现类中添加Transactional注解,保证事务完全
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper ;
    @Override
    public List<Map<String, Object>> selectRegister(String name, Integer page, Integer size) {
        return null;
    }

    @Override
    public User selectById(Integer id) throws Exception {
        User user = userMapper.selectById(id);
        if(user==null){
            throw new BusinessException(ExceptionCode.USER_NOT_FONUD);
        }
        return user;
    }

    @Override
    public Integer insert(User user) {
        user.setName("张三");
        user.setPhone("1256");
        return userMapper.insert(user);
    }
}
